package com.it.homework;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @author げっしょく
 * @date 2021/8/7
 */
public class T4Role extends Thread {
    private ArrayBlockingQueue<String> array;
    private int a ;
    public T4Role(ArrayBlockingQueue<String> array,int a) {
        this.array = array;
        this.a = a;
    }

    @Override
    public void run() {
        while (true) {
            if (a == 0){
                System.out.println("消费者以及吃饱了");
                break;
            }else{
                try {
                    String take = array.take();
                    System.out.println("消费者正在吃" + take );
                    a--;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}


class T4Role2 extends Thread {
    private ArrayBlockingQueue<String> array;
    private int a ;
    public T4Role2(ArrayBlockingQueue<String> array, int a) {
        this.array = array;
        this.a = a;
    }

    @Override
    public void run() {
        while (true) {
            if(a == 0){
                System.out.println("今天限卖的10个汉堡包以经做完了");
                break;
            }else{
                try {
                    array.put("汉堡包");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("厨师正在做汉堡包");
                a--;
            }
        }
    }
}
